package com.likersai.opon.controller;

import com.likersai.opon.pojo.entity.Menu;
import com.likersai.opon.pojo.bo.MenuTreeModel;
import com.likersai.opon.pojo.bo.PageBO;
import com.likersai.opon.pojo.bo.ResponseBO;
import com.likersai.opon.pojo.vo.req.menu.AddMenuReq;
import com.likersai.opon.service.MenuService;
import com.likersai.opon.service.param.menu.MenuQuery;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单相关接口
 *
 * @author sun.ye
 * @since 2021-03-13 23:57
 */
@RestController
@RequestMapping(value = "/menu")
public class MenuController {


    private final MenuService menuService;

    public MenuController(MenuService menuService) {
        this.menuService = menuService;
    }

    @PostMapping(value = "/queryMenuTree")
    @ApiOperation(value = "获取菜单树", notes = "获取菜单树")
    public ResponseBO<List<MenuTreeModel>> queryMenuTree(@RequestBody MenuQuery param){
        List<MenuTreeModel> result = menuService.queryMenuTree(param);
        return ResponseBO.getSuccess(result);
    }


    @PostMapping(value = "/queryMenu")
    @ApiOperation(value = "获取菜单清单", notes = "获取菜单清单")
    public ResponseBO<List<Menu>> queryMenu(@RequestBody MenuQuery param){
        List<Menu> result = menuService.queryMenu(param);
        return ResponseBO.getSuccess(result);
    }


    @PostMapping(value = "/queryMenuPage")
    @ApiOperation(value = "获取菜单分页", notes = "获取菜单分页")
    public ResponseBO<PageBO<Menu>> queryMenuPage(@RequestBody MenuQuery param){
        PageBO<Menu> result = menuService.queryMenuPage(param);
        return ResponseBO.getSuccess(result);
    }


    @PostMapping(value = "/saveMenu")
    @ApiOperation(value = "新增菜单", notes = "新增菜单")
    public ResponseBO<Menu> saveMenu(@RequestBody AddMenuReq req){
        Menu result = menuService.addMenu(req);
        return ResponseBO.getSuccess(result);
    }

}